package com.kkks.spring_rest.tick.dao;

import java.util.List;
import java.util.Map;

import org.springframework.jdbc.core.RowMapper;

import com.kkks.spring_rest.tick.dao.impl.Page;



/**
 * @author SC
 * @version 1.0
 * @created 2012-6-19 下午04:57:41
 * @describe
 */

public interface JdbcBaseDao<T> {

	/**@ tested
	 * 描述 执行一条 sql 语句
	 * 
	 * @param sql
	 * 
	 */
	public void execute(String sql);// TODO

	/**@ tested
	 * 描述 执行一组sql语句
	 * 
	 * @param sql
	 *            update ca_user set a ='newea' ,b=3 where c = 5
	 * @return an array containing the numbers of rows affected by each update
	 *         in the batch
	 */
	public int[] batchUpdate(String[] sql);// TODO

	/**@ tested
	 * 描述 执行一组sql语句 注意：这里的sql不支持 命名参数，只能用 ? 代替 update ca_user set a =? ,b=?
	 * where c = ?
	 * 
	 * @param sql
	 * @param object
	 * @return an array containing the numbers of rows affected by each update
	 *         in the batch
	 */
	public int[] batchUpdate(String sql, final List<Object[]> object);// TODO

	/**@ tested
	 * 描述 更新sql语句的执行，没有参数的情况
	 * 
	 * @param sql
	 * @return an array containing the numbers of rows affected by each update
	 *         in the batch
	 */
	public boolean update(String sql);// TODO

	/**@ tested
	 * 描述 多个参数的更新语句
	 * 
	 * @param sql
	 * @param objects
	 * @return 受影响的行数 boolean
	 */
	public boolean update(String sql, Object...objects);// TODO

	/**@ tested
	 * 描述 查询实体对象，泛型
	 * 
	 * @param <T>
	 * @param sql
	 * @param rowMapper
	 * @param args
	 * @return T
	 */
	@SuppressWarnings("hiding")
	public <T> T queryForEntity(String sql, RowMapper<T> rowMapper, Object... args);// TODO


	/**@ tested
	 * 描述 查询一条sql，返回列表
	 * 
	 * @param sql
	 * @return <Map<String,Object>>an List that contains a Map per row
	 */
	public List<Map<String, Object>> queryForEntityList(String sql);// TODO
	public Page queryForEntityPaginationList(String sql, int currentPage, int rowNum);// TODO
	/**@ tested
	 * 描述 带参数的列表查询
	 * 
	 * @param sql
	 * @param args
	 * @return a List that contains a Map per row
	 */
	public List<Map<String, Object>> queryForEntityList(String sql, Object... args);// TODO
	public Page queryForEntityPaginationList(String sql, int currentPage, int rowNum, Object... args);// TODO
	
	/**@ tested
	 * 描述 查询单列(类型为整型)，返回一个整数值
	 * 
	 * @param sql
	 *            select count(*) from demo where a =: a and b =: b select nid
	 *            from demo where a =: a and b =: b ;
	 * @param paramMap
	 * @return the result object of the required type, or null in case of SQL
	 *         NULL
	 */
	public Object queryForObject(String sql, Class<T> requiredType, Object...objects);// TODO
	/**@ tested
	 * 描述 泛型查询列表
	 * 
	 * @param <T>
	 * @param sql
	 *            elementType - the required type of element in the result list
	 *            (for example, Integer.class)
	 * @param elementType
	 * @return a List of objects that match the specified element type 即为基本的数据类型
	 */
	@SuppressWarnings("hiding")
	public <T> List<T> queryForObjectList(String sql, Class<T> elementType);// TODO
	public  Page queryForObjectPaginationList(String sql, Class<T> elementType, int currentPage, int rowNum);// TODO
	/**@ tested
	 * 描述 带参数的泛型查询
	 * 
	 * @param <T>
	 * @param sql
	 * @param elementType
	 *            - the required type of element in the result list (for
	 *            example, Integer.class)
	 * 这里的class只支持普通类型，且带此参数后，只能支持包含一列的查询，且不再有map。
	 * 对于结果集只含1列的查询，是比较好的接口。它会自动进行类型转换。如果转换出错，会抛异常。
	 * @param args
	 * @return a List of objects that match the specified element type
	 */
	@SuppressWarnings({ "hiding" })
	public <T> List<T> queryForObjectList(String sql, int[] argTypes, Class<T> elementType, Object... args);// TODO
	public Page  queryForObjectPaginationList(String sql, int[] argTypes, Class<T> elementType, int currentPage, int rowNum, Object... args);// TODO
}
